package com.tang.tasks.zentao;

import com.google.gson.JsonObject;
import com.intellij.icons.AllIcons;
import com.intellij.tasks.Comment;
import com.intellij.tasks.Task;
import com.intellij.tasks.TaskType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * Created by TangZX on 2017/1/10.
 */
public class ZentaoBUG extends Task {

    private Date parseDate(String name) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        try {
            return format.parse(jsonObject.get(name).getAsString());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    private JsonObject jsonObject;

    ZentaoBUG(JsonObject jsonObject) {

        this.jsonObject = jsonObject;
    }

    @NotNull
    @Override
    public String getId() {
        return jsonObject.get("id").getAsString();
    }

    @NotNull
    @Override
    public String getSummary() {
        return jsonObject.get("title").getAsString();
    }

    @Nullable
    @Override
    public String getDescription() {
        return "desc";
    }

    @NotNull
    @Override
    public Comment[] getComments() {
        return new Comment[0];
    }

    @NotNull
    @Override
    public Icon getIcon() {
        return AllIcons.Nodes.Advice;
    }

    @NotNull
    @Override
    public TaskType getType() {
        return TaskType.BUG;
    }

    @Nullable
    @Override
    public Date getUpdated() {
        return parseDate("lastEditedDate");
    }

    @Nullable
    @Override
    public Date getCreated() {
        return parseDate("openedDate");
    }

    @Override
    public boolean isClosed() {
        return false;
    }

    @Override
    public boolean isIssue() {
        return false;
    }

    @Nullable
    @Override
    public String getIssueUrl() {
        return null;
    }
}
